﻿document.addEventListener('DOMContentLoaded', function() {
	var defaultConfig = {enabled: false}; 
	chrome.storage.sync.get(defaultConfig, function(items) {
		document.getElementById('enabled').checked = items.enabled;
	});
});

document.getElementById('save').addEventListener('click', function() {
	document.getElementById('status').textContent = '1';
	var enabled = document.getElementById('enabled').checked;
	document.getElementById('status').textContent = enabled;
	// 这里貌似会存在刷新不及时的问题
	var cfg = {enabled: enabled}
	document.getElementById('status').textContent = cfg["enabled"];
	try{
		chrome.storage.sync.set(cfg, function() {
			// 注意新版的options页面alert不生效！
			// alert('保存成功！');
			document.getElementById('status').textContent = '保存成功！';
			//setTimeout(() => {document.getElementById('status').textContent = '';}, 8000);
		});
	} catch(err) {
		console.log('error')
		document.getElementById('status').textContent = err;
	}
});
